package com.java.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.java.entity.event.ShareInfoEvent;
import com.java.service.ShareService;
import com.java.util.resp.BaseRespone;
import com.java.util.resp.TableRespone;

@RestController
@RequestMapping("/admin")
public class ShareController {
	
	@Autowired private ShareService shareService;
	
	@PostMapping("/getShares")
	public TableRespone getShares(
			@RequestParam(required = false, defaultValue = "") String title,
			@RequestParam(required = false, defaultValue = "0") int page,
			@RequestParam(required = false, defaultValue = "0") int size) {
		return shareService.getShareList(null, title, page, size);
	}

	@PostMapping("/saveShare")
	public BaseRespone saveShare(@RequestBody ShareInfoEvent shareInfo) {
		
		return shareService.saveShare(shareInfo.getShareId(), "1", shareInfo.getShareTitle(), shareInfo.getShareSubtitle(), shareInfo.getShareText());
	}

	@PostMapping("/delShare")
	public BaseRespone delShare(@RequestParam(required = false) String shareId) {
		return shareService.delShare(shareId);
	}

}
